<?php

namespace App\Providers;

use AlibabaCloud\SDK\Green\V20220302\Green;
use AlibabaCloud\Tea\Utils\Utils\RuntimeOptions;
use Darabonba\OpenApi\Models\Config;
use Illuminate\Support\ServiceProvider;

class AliyunServiceProvider extends ServiceProvider
{
    public function register()
    {
        // 注册内容安全服务
        $this->app->singleton('aliyun.green', function ($app) {
            $config = new Config([
                'accessKeyId' => config('aliyun.access_key_id'),
                'accessKeySecret' => config('aliyun.access_key_secret'),
                'regionId' => config('aliyun.region_id'),
                'endpoint' => config('aliyun.green.endpoint'),
                'connectTimeout' => config('aliyun.green.connect_timeout', 5),
                'timeout' => config('aliyun.green.timeout', 15),
            ]);
            
            return new Green($config);
        });

        // 注册OSS服务（如果需要）
        $this->app->singleton('aliyun.oss', function ($app) {
            $config = new \OSS\OssClient(
                config('aliyun.access_key_id'),
                config('aliyun.access_key_secret'),
                config('aliyun.oss.endpoint'),
                false
            );
            
            $config->setTimeout(config('aliyun.oss.timeout', 3600));
            $config->setConnectTimeout(config('aliyun.oss.connect_timeout', 10));
            
            return $config;
        });
    }

    public function boot()
    {
        $this->publishes([
            __DIR__.'/../../config/aliyun.php' => config_path('aliyun.php'),
        ], 'config');
    }
}
